<template>
	
	<view class="container">
		<view class="qrcode">
			<view class="qrtitle">刁镇园区出入码</view>
			<view id="qrbox">
				<!-- 预约二维码 - 通过 -->
				<weapp-qrcode v-if="loadOver" :text="Text" :title="title"></weapp-qrcode>
			</view>
		</view>
		<view class="tips">
			<view>温馨提示: 本二维码仅支持单进单出，请勿多人使用。</view>
		</view>
	</view>
	
</template>

<script>
	
	import {
		Platform,Storage_Key,ProjectStates,ProjectKeys,CarSetting
	} from '@/static/config.js';
	import moment from 'moment'
	import { aesEncrypto, aesDecrypto } from '@/common/crypto.js'
	import BookingCarItem from "./components/booking-car/booking-car-item.vue"
	import BookingCarType from "@/pages/booking/components/booking-car/booking-car-type.vue"
	
	let that;
	export default {
		components: {
			BookingCarItem,
			BookingCarType
		},
		data() {
			return {
				// 数据列表
				listData: [],
				doquerytime: Date.now(), // 每次执行初始查询时 将其置为当时时间，后续分页以该时间为基准进行查询。
				//加载更多
				refreshing: false,
				wxUserInfo: [], //微信用户
				webUserInfo: [], //web平台用户
				Text:'',
				title:'',
				inCount:0,
				loadOver:false,
			}
		},
		beforeCreate() {
			that = this;
		},
		onLoad(options) {
			if (options && options.data) {}
			this.wxUserInfo = this.$storage.get(Storage_Key.user_info, true);
			this.webUserInfo = this.$storage.get(Storage_Key.web_user_info, true);
			this.initData(); // 设置监听
		},
		mounted() {},
		onShow() {},
		activated() {
		},
		/**
		 *  点击导航栏 buttons 时触发
		 */
		onNavigationBarButtonTap() {
		},
		onPullDownRefresh() { // 下拉刷新
			this.initData()
		},
		computed: {},
		methods: {
			initData(){
				let _self = this;
				let totalcount = -1;
				let formData = {
					pageIndex: 1,
					pageSize: 5,
					carCode: '',
					inStartTime: '',
					inEndTime: '',
					outStartTime: '',
					outEndTime: '',
					checkinState: '',
				};
				// 权限分类：根据webUserInfo判断是否平台用户，区别普通大众和平台账户
				formData.openid = this.wxUserInfo.openId;
				
				request({
					url: Platform.api_requestUrl + '/stp-checkin/getListDetail',
					data: formData,
					method: 'GET',
				}).then(res => {
					if (res.code == 200 && !!res.data) {
						let _list = res.data;
						let checkinid = '';
						let driver = '';
						let userid = '';
						let time = '';
						let job = '';
						let dest = '';
						// 找到最近的一次记录， 如果是进入，则拿到进入记录的id。 如果是出去，则应该进入园区，新增记录。
						if(_list && _list.length>0){
							_list[0].status && (_list[0].status == '1') && (checkinid = _list[0].id , time = _list[0].createtime);
							time == '' && (time = Date.now());
						}
						driver = this.webUserInfo.user.userName
						userid = this.webUserInfo.user.userId
						dest = this.webUserInfo.owner.name
						job = this.webUserInfo.job.find(e=>e==6)? 'qygeneral':'other'
						
						this.Text = Platform.tag + ',' + checkinid + "," + driver + ',' + this.wxUserInfo.openId + "," + userid + ',' + job
							+ ',' + dest ;
						
						let starttime = moment().format("YYYYMMDDHHmmss");
						let endtime = moment().add(5,'minutes').format("YYYYMMDDHHmmss");
							
						let encrypto = starttime + '|' + endtime + '|' + this.wxUserInfo.openId + '|' + '1,2,3,4,5,6'
						let encryptorslt = aesEncrypto(encrypto);
						
						// this.Text = encryptorslt;
						this.title = time;
						
						this.loadOver = true;
					}
				}).catch(error => {
					console.log("error")
				});
			},
			
			goDetail(item) {
				uni.navigateTo({
					url: '/pages/booking/booking-car-view?item=' + encodeURIComponent(JSON
						.stringify(item))
				})
			},
		},
		filters: {
	
		}
	}
</script>

<style>
	
	.container{
		width:100%;
		height:100%;
		padding:5px;
	}
	.qrcode{
		margin-bottom: 15upx;
	}
	.qrbox{
		height: 500px;
	}
	.qrtitle{
		height: 36px;
		line-height: 36px;
		text-align: center;
	}
	.tips{
		text-align: center;
	}
	
</style>